﻿using RightControl.Common;
using RightControl.IService;
using RightControl.Model;
using System.Web.Mvc;

namespace RightControl.WebApp
{
    public class HandlerErrorAttribute : HandleErrorAttribute
    {
        private ILogService logService;
        public override void OnException(ExceptionContext context) {
            //context.RequestContext.HttpContext.Response.Clear();
            base.OnException(context);
            context.ExceptionHandled = true;
            context.HttpContext.Response.StatusCode = 200;

            //LogModel logEntity = new LogModel();
            //logEntity.ModuleName = "系统异常";
            //logEntity.LogType = DbLogType.Exception.ToString();
          
            //logEntity.Status = true;
            //logEntity.Description = context.Exception.Message;
            //logService.WriteDbLog(logEntity);

            context.Result = new ContentResult { Content = new AjaxResult { state = ResultType.error.ToString(), message = context.Exception.Message }.ToJson() };
        }
        //private void WriteLog(ExceptionContext context)
        //{
        //    if (context == null)
        //        return;
        //    var log = LogFactory.GetLogger(context.Controller.ToString());
        //    log.Error(context.Exception);
        //}
    }
}